package com.eva.oss.api;

import com.eva.framework.common.api.BaseController;
import com.eva.framework.common.model.ApiResponse;
import com.eva.framework.oss.OSSUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import jakarta.annotation.Resource;

@Tag(name = "OSS文件上传")
@RestController
@RequestMapping("/resource/oss/upload")
public class OSSFileUploadController extends BaseController {

    @Resource
    private OSSUtil ossUtil;

    @Operation(summary = "上传图片，最大为5M")
    @PostMapping("/image")
    public ApiResponse<OSSUtil.UploadResult> uploadImage(@RequestParam("file") MultipartFile file) {
        return ApiResponse.success(ossUtil.setMaxSize(5).uploadImage(file));
    }

    @Operation(summary = "上传文件")
    @PostMapping("/attach")
    public ApiResponse<OSSUtil.UploadResult> uploadFile(@RequestParam("file") MultipartFile file) {
        return ApiResponse.success(ossUtil.upload(file));
    }
}
